import java.io.BufferedReader;

public class CalendarSeeker {
	public static final String[] DAYS_OF_WEEK = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
	public static final int WRONG_DAY = 8;
	public static final int WRONG_MONTH = 9;
	public static final int WRONG_YEAR = 10;
	private static final int FEBRUARY = 2;

	public static int getDayOfTheWeek(int day, int month, int year) {
		final int a = (14 - month) / 12;
		final int y = year - a;
		final int m = month + 12*a - 2;
		final int[] daysInMonth = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
		
		if (month < 1 || month > 12) {
			return WRONG_MONTH;
		}
		
		if (day < 1 || day > daysInMonth[month - 1]) {
			return WRONG_DAY;
		} else {
			if (month == FEBRUARY && 
				(year % 4 != 0 ||(year % 100 == 0 && year % 400 != 0)) && 
				(day > daysInMonth[month - 1] - 1)) {
				return WRONG_DAY;
			}
		}
		
		if (year < 1) {
			return WRONG_YEAR;
		}
		
		return (7000 + (day + y + y/4 - y/100 + y/400 + (31*m) / 12)) % 7;
	}
	public static void main(String[] args) {
		BufferedReader consoleReader = new BufferedReader(new java.io.InputStreamReader(System.in));
		int day, month, year;
		int dayOfWeek;
		
		System.out.println("Calendar seeker");
		
		try {
			System.out.println("Enter date:");
			System.out.print("Day: ");
			day = new Integer(consoleReader.readLine()).intValue();
			System.out.print("Month: ");
			month = new Integer(consoleReader.readLine()).intValue();
			System.out.print("Year: ");
			year = new Integer(consoleReader.readLine()).intValue();
			
			dayOfWeek = CalendarSeeker.getDayOfTheWeek(day, month, year);
			
			if (dayOfWeek >= 0 && dayOfWeek < DAYS_OF_WEEK.length) {
				System.out.println("\nDay of the week: " + CalendarSeeker.DAYS_OF_WEEK[dayOfWeek]);
			} else {
				switch (dayOfWeek) {
					case WRONG_DAY: 
						System.out.println("Wrong number of the day.");
						break;
					case WRONG_MONTH: 
						System.out.println("Wrong number of the month.");
						break;
					case WRONG_YEAR: 
						System.out.println("Wrong number of the year.");
						break;
				}
			}
		} catch (java.lang.NumberFormatException  ex) {
			System.out.println("Error! Wrong number.");
			return;
		} catch (java.io.IOException ex) {
			System.out.println("Caught IO error!");
			System.out.println(ex);
			return;
		}
		
		
	}
}